package com.lyf.scm.admin.domain.remote.allocationservice.facade;

import com.alibaba.fastjson.JSONObject;
import com.lyf.scm.admin.domain.remote.allocationservice.BigDataGeneralHandlerRemote;
import com.lyf.scm.admin.domain.remote.allocationservice.dto.ActualSalesQtyQueryDTO;
import com.lyf.scm.common.enums.ResponseMsg;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.core.exception.RomeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 大数据通用处理类（日补货接口）
 *
 * @author wangchlei
 * @date 2020/10/13
 */
@Service
@Slf4j
public class BigDataGeneralHandlerFacade {
    @Resource
    private BigDataGeneralHandlerRemote bigDataGeneralHandlerRemote;

    /**
     * 大数据任务补救接口
     *
     * @param
     * @return void
     **/
    public void remedyBigDataJob() {
        Response response = bigDataGeneralHandlerRemote.remedyBigDataJob();
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
    }

    /**
     * 根据渠道、区域、sku聚合查询实际销量
     * @author wuyuanhang
     * @date 2020/11/11
     * @param
     * @return Map<String, List<BigDecimal>>
     */
    public Map<String, List<BigDecimal>> groupByChannelAreaSku(){
        ActualSalesQtyQueryDTO dto = new ActualSalesQtyQueryDTO();
        log.info("入参：{}", JSONObject.toJSONString(dto));
        Response<Map<String, List<BigDecimal>>> response = bigDataGeneralHandlerRemote.groupByChannelAreaSku(dto);
        log.info("返回结果：{}", JSONObject.toJSONString(response));
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    /**
     * echart图查询实际销量，传dateList、startTime、endTime以及其他条件，如渠道、区域、品类、sku
     * @author wuyuanhang
     * @date 2020/11/11
     * @param
     * @return  List<BigDecimal>
     */
    public List<BigDecimal> groupByDate(){
        ActualSalesQtyQueryDTO dto = new ActualSalesQtyQueryDTO();
        log.info("入参：{}", JSONObject.toJSONString(dto));
        Response<List<BigDecimal>> response = bigDataGeneralHandlerRemote.groupByDate(dto);
        log.info("返回结果：{}", JSONObject.toJSONString(response));
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }
}
